﻿/*
 * 树，无线循环列表
 * item 可折叠类
 * 
 */
using System;
using UnityEngine;
using UnityEngine.UI;

namespace SuperScrollView
{
    public class SuperTreeItem : SuperTreeBaseItem
    {
        public GameObject mArrow;
        public Button mExpand;
        int mTreeItemIndex = -1;
        Action<int> mClickExpandHandler;

        public int TreeItemIndex
        {
            get { return mTreeItemIndex; }
        }

        public override void Init()
        {
            base.Init();
            mType = SuperTreeItemType.Tree;
            mExpand.onClick.AddListener(OnButtonClicked);
        }

        public void SetClickCallBack(Action<int> clickHandler)
        {
            mClickExpandHandler = clickHandler;
        }

        void OnButtonClicked()
        {
            if (mClickExpandHandler != null)
            {
                mClickExpandHandler(mTreeItemIndex);
            }
        }
        public void SetExpand(bool expand)
        {
            if (expand)
            {
                mArrow.transform.localEulerAngles = new Vector3(0, 0, -90);
            }
            else
            {
                mArrow.transform.localEulerAngles = new Vector3(0, 0, 0);
            }
        }

        public void SetItemData(int treeItemIndex, bool expand, bool isCanExpand)
        {
            mTreeItemIndex = treeItemIndex;
            SetExpand(expand);
            RefreshItem();
            SetArrowVisable(isCanExpand);
        }

        public void SetArrowVisable(bool isShow)
        {
            mExpand.gameObject.SetActive(isShow);
        }

    }
}

